package com.lee.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lee.entity.SysUser;
import com.lee.service.impl.SysMemberServiceFeign;
import com.lee.service.SysUserService;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.List;

@RestController
@RequestMapping("/sysUser")
public class SysUserController {

    @Autowired
    private SysUserService sysUserService ;
    @Autowired
    private SysMemberServiceFeign sysMemberServiceFeign ;
    @Autowired
    private RestTemplate restTemplate ;

    @GetMapping("findUserList")
    public Object findUserList(){

        QueryWrapper<SysUser> userQueryWrapper = new QueryWrapper<>();
        userQueryWrapper.eq("is_delete","0");

        List<SysUser> list = sysUserService.list(userQueryWrapper);

        return list;
    }

    @GetMapping("saveUser")
    @GlobalTransactional(name = "my_test_tx_group")
    public Object saveUser(){

       SysUser sysUser = new SysUser();
       sysUser.setPost("php");
       sysUser.setUserName("lisi");

       sysUserService.save(sysUser);

       sysMemberServiceFeign.saveMember();

        // 调用积分
        int i=1/0 ;

        return "ok";
    }
}
